package com.sky.controller.admin;

import com.sky.dto.*;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@ApiOperation("商家订单管理")
@Slf4j
@RequestMapping("/admin/order")
public class OrderController {
    @Autowired
    private OrderService orderService;
    @GetMapping("conditionSearch")
    public Result<PageResult> conditionsearch(OrdersPageQueryDTO ordersPageQueryDTO){
       PageResult pageResult= orderService.condition(ordersPageQueryDTO);
       return Result.success(pageResult);
    }
    @GetMapping("statistics")
    public Result<OrderStatisticsVO> statistics(){
      OrderStatisticsVO orderStatisticsVO=orderService.statistics();
        return Result.success(orderStatisticsVO);
    }
    @GetMapping("details/{id}")
    public Result<OrderVO> orderDetail(@PathVariable Long id){
      OrderVO orderVO= orderService.selectByOrderId(id);
      return Result.success(orderVO);
    }
    @PutMapping("confirm")
    public Result orderReceive(@RequestBody OrdersConfirmDTO confirmDTO){
     orderService.ReceiveOrder(confirmDTO);
        return Result.success();
    }

    /**
     * 取消订单
     * @param 、、ordersRejectionDTO
     * @return
     */
    @PutMapping("cancel")
    public Result orderCancel(@RequestBody OrdersCancelDTO ordersCancelDTO){
        orderService.CancelOrder(ordersCancelDTO);
        return Result.success();
    }
    @PutMapping("complete/{id}")
    public Result ordercomplete(@PathVariable Long id){
        orderService.complete(id);
        return Result.success();
    }
    @PutMapping("rejection")
    public Result orderRejiect(@RequestBody OrdersRejectionDTO ordersRejectionDTO){
        orderService.RejectOrder(ordersRejectionDTO);
        return Result.success();
    }
    @PutMapping("delivery/{id}")
    public Result orderRejiect(@PathVariable Long id){
        orderService.deliver(id);
        return Result.success();
    }
}
